// /common/http.api.js

// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
// let indexUrl = '/api/index';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 首页
	let index = (params = {}) => vm.$u.get('/api/index', params);
	
	
	// 认证相关
	const authLogin = params => vm.$u.post('/api/auth/login', params);  //登陆
	const register = params => vm.$u.post('/api/auth/register', params);  //注册
	const authLogout = () => vm.$u.post('/api/auth/logout');  //退出
	const authOssToken = () => vm.$u.get('/api/auth/oss/token');  //OSS Token
	// 个人中心
	const userinfo = () => vm.$u.get('/api/user');  // 用户详情
	const changeName = params => vm.$u.put('/api/user', params);  // 更改用户名
	const userAvatar = params => vm.$u.post('/api/user/avatar', params);  // 更改用户头像
	// 商品相关
	const goodsInfo = id => vm.$u.get(`/api/goods/${id}`);  // 商品详情
	const goodsSc = id => vm.$u.post(`/api/collects/goods/${id}`);  // 收藏商品collects = ()
	const mycollects = data => vm.$u.get('/api/collects',data);  // 我的收藏
	//购物车
	const addCart = params => vm.$u.post('/api/carts', params);  // 添加购物车
	const cartList = include => vm.$u.get('/api/carts/?'+include);  // 购物车列表
	const checkedCart = params => vm.$u.patch('/api/carts/checked', params);  // 选中商品购物车状态
	const modifyCart = (id,params) => vm.$u.patch(`/api/carts/${id}`, params);  // 改变购物车数量
	const delCart = id => vm.$u.delete(`/api/carts/${id}`);  // 删除购物车商品
	//商品分类
	const goodsList = params => vm.$u.get('/api/goods', params);  //商品列表
	//地址管理
	const addAddress = params => vm.$u.post('/api/address', params);  // 添加地址
	const editAddress = (id,params) => vm.$u.put(`/api/address/${id}`,params);  // 修改地址
	const delAddress = id => vm.$u.delete(`/api/address/${id}`);  // 删除地址
	const addressList = () => vm.$u.get('/api/address');  // 地址列表
	const getAddressDetail = id => vm.$u.get(`/api/address/${id}`);  // 地址详情
	//订单相关
	const ordersView = () => vm.$u.get('/api/orders/preview');  // 订单预览
	const createOrder = params => vm.$u.post('/api/orders',params);  // 提交订单
	const payOrder = (order,data) => vm.$u.get(`/api/orders/${order}/pay`,data);  // 订单支付
	const payOrderStatus = order => vm.$u.get(`/api/orders/${order}/status`);  // 查询订单状态
	const getOrderDetail = (order,include) => vm.$u.get(`/api/orders/${order}`,include);  //订单详情
	const ordersList = params => vm.$u.get('/api/orders',params);  // 订单列表
	//商品管理后台
	const admingoods = params => vm.$u.get('/api/admin/goods',params);  //后台商品列表
	const editgoods = good => vm.$u.patch(`/api/admin/goods/${good}/on`);  //商品上下架
	const userres = params => vm.$u.get('/api/admin/users',params);  //会员列表
	const edituser = user => vm.$u.patch(`/api/admin/users/${user}/lock`);  //禁用和启用会员
	const edituserinfo = (users,params) => vm.$u.put(`/api/admin/users/${users}`,params);  // 修改会员信息
	const userDetail = (user) => vm.$u.get(`/api/admin/users/${user}`);  //会员详情
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		index,
		authLogin,
		register,
		userinfo,
		authLogout,
		changeName,
		authOssToken,
		userAvatar,
		goodsInfo,
		goodsSc,
		addCart,
		cartList,
		goodsList,
		checkedCart,
		modifyCart,
		delCart,
		addAddress,
		addressList,
		ordersView,
		getAddressDetail,
		editAddress,
		delAddress,
		mycollects,
		createOrder,
		payOrder,
		payOrderStatus,
		getOrderDetail,
		ordersList,
		admingoods,
		editgoods,
		userres,
		edituser,
		edituserinfo,
		userDetail,

	};
}

export default {
	install
}